package main

import (
	"fmt"
	"github.com/360EntSecGroup-Skylar/excelize"
)

var systemName = "营运车平台"

var excelName = "营运车平台-数据表列信息.xlsx"

var sheetName = "sheet2"

func main() {
	SetupDb()
	system := createSystem(systemName)
	f, err := excelize.OpenFile(excelName)
	if err != nil {
		fmt.Println(1, err)
		return
	}
	rs, err := f.Rows(sheetName)
	if err != nil {
		fmt.Println(err)
		return
	}
	rs.Next()
	var currentTable = &Table{}
	for rs.Next() {
		//fmt.Println(len(rs.Columns()))
		r := rs.Columns()
		if len(r) == 0 {
			continue
		}
		if r[0] != "" {
			var table = Table{
				SystemId: system.ID,
				Name:     r[0],
				Desc:     r[1],
			}
			currentTable = createTable(table)
		}
		var column = Column{
			TableId:       currentTable.ID,
			Name:          r[2],
			Desc:          r[4],
			Type:          r[6],
			IsMain:        r[7] == "是",
			IsEmptyable:   r[8] == "是",
			DictType:      r[9],
			SubDictSystem: r[10],
			DictGroupFlag: r[11],
			DictColumn:    r[12],
			SubDictType:   r[13],
			ColumnSize:    r[16],
			ColumnSuffix:  r[17],
		}
		createColumn(column)
	}

}

func newTable() {

}
